package me.leon.ade

import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.text.method.LinkMovementMethod
import android.util.Log
import android.view.View
import android.widget.Toast
import io.github.leon406.view.textview.TouchClickSpan
import me.leon.ade.databinding.ActivityEditTextBinding
import me.leon.ext.android.SpanUtils

class EditTextActivity : AbsBindingActivity<ActivityEditTextBinding>() {

    override fun ActivityEditTextBinding.init() {

        ltv.addLinkSpanListener { Log.w("LinkTextView", "sssss click $it") }
        val span =
            SpanUtils.with(stt1)
                .setForegroundColor(Color.YELLOW)
                .append("_____")
                .append("用户协议")
                .setForegroundColor(Color.YELLOW)
                .setClickSpan(
                    object : TouchClickSpan() {
                        override fun onSpanClick(widget: View?) {
                            show("111")
                        }
                    }
                )
                .append("隐私1111111111111:")
                .append("隐私协议")
                .setForegroundColor(Color.YELLOW)
                .setClickSpan(
                    object : TouchClickSpan() {
                        override fun onSpanClick(p0: View?) {
                            show("111")
                        }
                    }
                )
                .create()

        tv.movementMethod = LinkMovementMethod.getInstance()

        tv.setOnClickListener { Log.w("llll", "tv clicked $it") }
        tv.text = span
        stt1.text = span
        stt1.setOnClickListener { Log.w("llll", "stt1 clicked $it") }
        stt1.setMovementMethodDefault()
    }

    companion object {
        fun start(context: Context) {
            context.startActivity(
                Intent(context, EditTextActivity::class.java).apply {
                    addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                }
            )
        }
    }
}

fun Context.show(msg: String) {
    Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
}
